// 请求接口
import { getList, addOrder,deleteOrder,getInfo,editOrder ,orderChart} from '@/api/order'

import Qs from 'qs'


const state = {}

const mutations = {


}

const actions = {

  // 获取订单列表信息
  async getList({commit},serchForm) {
    // console.log(serchForm);
    let res = await getList(serchForm);
    return res
  },
  // 删除订单信息
  async deleteOrder({},id) {
    let res = await deleteOrder(id);
    return res
  },
  // 添加订单信息
  async addOrder({},orderForm) {
    const res = await addOrder(orderForm);
    return res
  },
  // 获取单个订单信息
  async getInfo({},id) {
    console.log(id+"store");
    const res = await getInfo(id);
    console.log(res);
    return res
  },
  // 修改单个订单信息
  async editOrder({},orderInfo) {
    
    // const params = Qs.stringify(Info)
    const res = await editOrder(orderInfo.id,orderInfo);
    return res
  },
  // 获取订单统计数据
  async orderChart({},serchForm) {


    let {productId,levelId,time} = serchForm

    let res ;
      if(time.length > 1) {
          res = await orderChart({product:{id:productId},student:{level:{id: levelId} },createTime:time[0],updateTime:time[1]});
      }else{
        // 没有时间的查询
          res = await orderChart({product:{id:productId},student:{level:{id: levelId}}});
      }
   

    return res
  }
  
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

